<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 任务分类信息模型
 *
 * Class Category
 * @property $tasks
 * @package App\Models
 */
class Category extends Model
{
	/**
	 * 定义可批量填充字段
	 *
	 * @var array
	 * Date: 2018/2/5
	 * @author George
	 */
    public $fillable = [
        'name', 'scope'
    ];

    /**
     * 获取分类的任务
     *
     * Data: 2018/1/29
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function tasks(){
        return $this->belongsToMany(Task::class, 'category_task_pivot', 'category_id', 'task_id');
    }

    /**
     * 获取分类的门店数
     *
     * @author Eric
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function shops(){
        return $this->hasMany(Shop::class, 'category_id', 'id');
    }


}
